﻿using System;
using System.Windows.Media;
using System.Collections.Generic;

namespace ClassRoom.Controls
{

    /// <summary>
    /// Contains helper methods for use by the ColorPicker control.
    /// </summary>
    internal class ColorSpace
    {
        private const byte MIN = 0;
        private const byte MAX = 255;

        public static Color GetColorFromPosition(double position)
        {         
            position = position / 360;
            if (position >= 1)
                position = 0;
            position = 6 * position;
            int hueFloor = (int)Math.Floor(position);
            byte a = (byte)Math.Round(MAX * 1 * (1.0 - 1));
            byte b = (byte)Math.Round(MAX * 1 * (1.0 - (1 * (position - hueFloor))));
            byte c = (byte)Math.Round(MAX * 1 * (1.0 - (1 * (1.0 - (position - hueFloor)))));
            byte d = (byte)Math.Round((double)MAX);

            switch (hueFloor)
            {
                case 0: return Color.FromArgb(MAX, d, c, a);
                case 1: return Color.FromArgb(MAX, b, d, a);
                case 2: return Color.FromArgb(MAX, a, d, c);
                case 3: return Color.FromArgb(MAX, a, b, d);
                case 4: return Color.FromArgb(MAX, c, a, d);
                case 5: return Color.FromArgb(MAX, d, a, b);
                default: return Color.FromArgb(MAX, 255, 255, 255);
            }          
        } 
    }
}

